<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>iOS WIFI SDK调研</title>
		
		<style type="text/css">
			
			body{
				margin: auto; 
				width: 800px; 
				/*border: 1px solid #000;*/
			}
			
			.btn{
				float: left; 
				width: 120px; 
				height: 100%; 
				line-height: 120px; 
				text-align: center;
				margin-left: 20px;
				border-radius: 50%;
				border: 1px solid #555;
			}
			
			div {
				background-color: #f8f8f8;
				padding: 10px;
				font-size: 15px;
			}
			
			.desc{
				font-size: 12px;
				color: #555555;
			}
			
		</style>
	</head>
	
	<body>
		
		<h3>简述</h3>
		
		<div>
			The NEHotspotHelper interface allows an app to participate in the process of joining Wi-Fi/hotspot networks. Such an app is referred to as a Hotspot Helper. A Hotspot Helper receives commands to be processed in the background that allow it to participate in the Hotspot Network state machine. For more information, see Hotspot Network Subsystem Programming Guide.<br>
			NEHotspotHelper 接口允许一个APP获取已经加入的Wi-Fi/热点。这样的App被称为热点帮助器。热点帮助器在后台处理接收到的命令。<a href="https://developer.apple.com/documentation/networkextension/nehotspothelper">更多教程地址</a> <br><br>
			The Hotspot Network Subsystem allows a Hotspot Helper application to participate in the process of classifying and authenticating to Wi-Fi hotspot networks. This programming guide is a companion to Apple’s NEHotspotHelper Class Reference, which describes the Hotspot Helper API.
A Hotspot Helper application receives commands to be processed and provides a response to a command after it has been processed. In most instances, application command processing occurs while the application is running in the background.<br>
The application receives commands to process as part of two main functions: authentication and scan list filtering. These functions and their recommended implementations are described in the following sections
				
		</div>
		
		<h3>注意事项</h3>
		<div id="">
		1.首先，NEHotspotHelper 只在 iOS 9 及以上版本得到支持，之前版本的 iOS 并不支持该功能；<br><br>

		2.该框架目前还没有大规模开放使用，所以需要向苹果发送申请并且审核通过才能够获得使用该框架的权限，大致内容就是描述一下你需要使用该框架的原因之类的，建议使用的英文进行描述，中文也行。提交申请后大概一周内会收到反馈邮件，申请地址为： <a href="https://developer.apple.com/contact/network-extension/ ">https://developer.apple.com/contact/network-extension/ </a>。
		</div>
		
		<h3>用来做什么</h3>
		
		<div id="">
			
			1.&nbsp;获取wifi列表<br>
				<span class="desc">
					1.1&nbsp;NEHotspotHelper要获得wifi列表，需要进入到【无线局域网】设置页面才能获取 wifi 列表。苹果这么搞也是不好玩，还要进入到他自己的设置页面才能获取wifil列表，略显鸡肋~~~<br>
				</span>
			
				<span class="desc">
					1.2&nbsp;NEHotspotHelper提供的API里面没有主动获取WiFi列表的方法，只有一个回调方法来处理WiFi信息，也就是说这个回调什么时候执行是由系统决定的，你只能等着接收，首先你要保证注册成功，returnType等于Yes。<br><br>
				</span>
			
			
			2.&nbsp;连接wifi<br>
			<span class="desc">
				2.1&nbsp;必须先执行第1步，才能检测到指定 WiFi 可设定密码直接连接(连接的时候不需要输入密码,但是要连接需要手动打开系统的wifi列表)<br><br>
			</span>
			
			<span style="text-decoration: line-through;color: #555555;">3.&nbsp;创建热点<br></span>
			<span class="desc">
				3.1 没有发现可以创建热点的API和第三方APP
			</span>
		</div>
		
		<h3>同类产品分析</h3>
		
		<div>
			
			<h4>采样App</h4>
			
			1.<a href="https://itunes.apple.com/cn/app/wifi%E4%B8%87%E8%83%BD%E9%92%A5%E5%8C%99-%E5%AE%89%E5%85%A8wi-fi%E4%B8%80%E9%94%AE%E8%BF%9E/id919854496?mt=8">WiFi万能钥匙</a><br>
			2.<a href="https://itunes.apple.com/cn/app/wifi%E9%92%A5%E5%8C%99%E7%AE%A1%E5%AE%B6-wifi%E4%B8%87%E8%83%BD%E5%AF%86%E7%A0%81%E6%9F%A5%E7%9C%8B/id1245035646?mt=8">WIFI钥匙管家</a><br>
			3.<a href="https://itunes.apple.com/cn/app/wifi%E9%92%A5%E5%8C%99-%E4%B8%87%E8%83%BD%E7%9A%84wifi%E9%92%A5%E5%8C%99%E7%A5%9E%E5%99%A8/id1220819268?mt=8">WiFi钥匙</a><br>
			4.<a href="https://itunes.apple.com/cn/app/360%E5%85%8D%E8%B4%B9wifi-%E4%B8%80%E9%94%AE%E8%BF%9E%E6%8E%A5wifi%E7%9A%84%E5%AE%89%E5%85%A8%E7%AE%A1%E5%AE%B6/id942885362?mt=8">360免费WiFi</a><br>
			5.<a href="https://itunes.apple.com/cn/app/%E8%85%BE%E8%AE%AFwifi%E7%AE%A1%E5%AE%B6-%E6%89%8B%E6%9C%BA%E5%AE%89%E5%85%A8%E4%B8%87%E8%83%BDwifi/id1001153553?mt=8">腾讯WiFi管家</a><br><br>
			<h4>分析</h4>
				打开这些App都可以看到一些wifi的列表，但是这些wifi列表跟系统的wifi页面的wifi列表是不一样的。当选择其中一个wifi加入的时候，都会"提示用户自行到系统wifi页面，手动连接此App给出的wifi"只是不需要输入密码。
		</div>
		
		<h3>示例代码</h3>
		
		<div id="">
			
			1.导入头文件<br>
			#import&lt;NetworkExtension/NetworkExtension.h&gt;
			<br><br>
			
			2.然后使用如下代码即可将 WiFi 列表信息打印到 XCode 控制台，注意：这里需要打开系统 设置 中的 无线局域网 页面才能获取相关信息，因为打开该页面系统刷新 WiFi 信息时才会触发该回调：
<pre>
	<code>
				
- (void)scanWifiInfos{
    NSLog(@"1.Start");
    
    NSMutableDictionary* options = [[NSMutableDictionary alloc] init];
    [options setObject:@"EFNEHotspotHelperDemo" forKey: kNEHotspotHelperOptionDisplayName];
    dispatch_queue_t queue = dispatch_queue_create("EFNEHotspotHelperDemo", NULL);
    
    NSLog(@"2.Try");
    BOOL returnType = [NEHotspotHelper registerWithOptions: options queue: queue handler: ^(NEHotspotHelperCommand * cmd) {
        
        NSLog(@"4.Finish");
        NEHotspotNetwork* network;
        if (cmd.commandType == kNEHotspotHelperCommandTypeEvaluate ||
         cmd.commandType == kNEHotspotHelperCommandTypeFilterScanList) {
            // 遍历 WiFi 列表，打印基本信息
            for (network in cmd.networkList) {
                NSString* wifiInfoString = [[NSString alloc] initWithFormat: @"---------------------------\nSSID: %@\nMac地址: %@\n信号强度: %f\nCommandType:%ld\n---------------------------\n\n", network.SSID, network.BSSID, network.signalStrength, (long)cmd.commandType];
                NSLog(@"%@", wifiInfoString);
                
                // 检测到指定 WiFi 可设定密码。前提是你的事先知道这个wifi的密码
                if ([network.SSID isEqualToString: @"测试 WiFi"]) {
                    [network setConfidence: kNEHotspotHelperConfidenceHigh];
                    [network setPassword: @"123456789"];
                    NEHotspotHelperResponse *response = [cmd createResponse: kNEHotspotHelperResultSuccess];
                    NSLog(@"Response CMD: %@", response);
                    [response setNetworkList: @[network]];
                    [response setNetwork: network];
                    [response deliver];
                }
            }
        }
    }];
    
    // 注册成功 returnType 会返回一个 Yes 值，否则 No
    NSLog(@"3.Result: %@", returnType == YES ? @"Yes" : @"No");
}
				
	</code>
</pre>
		</div>
		
		<h3>申请使用权限</h3>
		<div id="">
			1.首先向苹（"networkextension@apple.com"）发邮件申请使用权限<br>
			2.邮件格式<br>
			<pre>
				
XXXXXXXX

Team ID: XXXXXXXXXX
Team Memberships: Apple Developer Program
Company / Organization: XXXXXXXXXX
Company / Product URL: http://www.XXXXXXXX.XXX/

What's your product's target market?
Consumer

What's your company's primary function?
Carrier

Describe your application and how it will use the Network Extension framework.
This application can help users to achieve a more efficient and convenient virtual private network function, the user can customize the rules to achieve different network operations for different processing. This application will use Extension framework Network to take over the user's selected application network requests, and according to the rules of the user to develop rules for them to deal with the corresponding.

What type of entitlement are you requesting?
App Proxy

Which platform does your application support?
iOS

Which IP protocol does your application support?
IPv4, IPv6

Which Transport protocol does your application support?
TCP

Which VPN protocol does your application support? (VPN solutions only)


Which Network layer does your application support? (VPN solutions only)


Which authentication protocol does your solution utilize? (VPN solutions only)


Which authentication protocol does your solution utilize? (Content Filter solutions only)
Username/Password

What authentication protocol does your solution utilize? (Hotspot Helper solutions only)


Does your solution contain or integrate with an MDM server?
No

Does your solution integrate with a cloud service? (Content Filter, VPN, MDM)
No

				
			</pre>
			
		</div>
		
		
		<h3>其他</h3>
		<div>
			sds
			
		</div>
	</body>
</html>
